import axios from 'axios';

const state = {
  orderItems: [] 
}

const mutations = {
  UPDATE_ORDER_ITEMS (state, payload) {
    state.orderItems = payload;
  }
}

const actions = {
  getOrderItems ({ commit }) {
    axios.get(`/orderList`).then((response) => {
      console.log(response.data.body);
      commit('UPDATE_ORDER_ITEMS', response.data.body)
    });
  },
  doSeckill ({ commit }, seckillGood) {
    var id = seckillGood.id;
    return axios.post(`/doSeckill?goodsId=` + id);
  },
  findSeckill ({ commit }, seckillGood) {
    var id = seckillGood.id;
    return axios.get(`/findSeckill?goodsId=` + id);
  },
  payOrder ({ commit }, orderItem) {
    var id = orderItem.id;
    return axios.post(`/payOrder?orderId=` + id).then((response) => {
      console.log(response.data);
    });
  }
}

const getters = {
  orderItems: state => state.orderItems
}

const orderModule = {
  state,
  mutations,
  actions,
  getters
}

export default orderModule;